package com.scqzy.shengchunqiang.sword2offer.day13;

import org.springframework.util.ObjectUtils;

/**
 * @Description: 剑指 Offer 58 - I. 翻转单词顺序
 * @Author 盛春强
 * @Date 2021/8/19 17:39
 */
public class ReverseWords {
    public String reverseWords(String s) {
        if (ObjectUtils.isEmpty(s)) {
            return null;
        }
        String[] split = s.split(" ");
        StringBuilder stringBuilder = new StringBuilder();
        for (int i = split.length - 1; i >= 0; i--) {
            if (!"".equals(split[i])) {
                stringBuilder.append(split[i]).append(" ");
            }
        }
        return stringBuilder.toString().trim();
    }
}
